package com.aqie.easy.math;

/**
 * 507. 完美数: 和除了它自身以外的所有正因子之和相等
 */
public class CheckPerfectNumber {
    public static boolean checkPerfectNumber(int num) {
        if (num == 1) return false;
        int sum = 0,i = 2;
        for(; i< Math.sqrt(num); i++){
            if (num % i == 0){
                sum += i;
                sum += num / i;
            }
        }
        if (i * i == num){
            sum += i;
        }
        sum += 1;
        return sum == num;
    }

    public static void main(String[] args) {
        // 找一个数的所有正因子 排除自身
        int num = 36;
        System.out.println(checkPerfectNumber(36));
        System.out.println(checkPerfectNumber(28));

    }
}
